package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.TInterference;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IInterferenceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: Stanley.Y
 * @Date: 2024/6/18 15:05
 * @Description: 干扰源数据管理Controller类
 * @Version 1.0.0
 */

@RestController
@Anonymous
@RequestMapping("/system/interference")
public class InterferenceDataController extends BaseController {

    @Autowired
    private IInterferenceDataService interferenceDataService;

    /**
     * 获取所有干扰源数据
     * @return
     */
    @GetMapping("/getInterferenceDataList")
    public AjaxResult getInterferenceDataList(){
        return success(interferenceDataService.getInterferenceDataList());
    }

    /**
     * 获取干扰源数据列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:interference:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInterference interference) {
        startPage();
        List<TInterference> list = interferenceDataService.selectInterferenceDataList(interference);
        return getDataTable(list);
    }

    /**
     * 根据干扰源主键ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:interference:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        TInterference result = interferenceDataService.selectInterferenceDataById(id);
        return success(result);
    }

    /**
     * 新增干扰源数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:interference:add')")
    @Log(title = "干扰源数据维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TInterference interference) {
        interference.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return toAjax(interferenceDataService.insertInterferenceData(interference));
    }

    /**
     * 修改干扰源数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:interference:edit')")
    @Log(title = "干扰源数据维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TInterference interference)
    {
        return toAjax(interferenceDataService.updateInterferenceData(interference));
    }

    /**
     * 删除干扰源数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:obstacle:remove')")
    @Log(title = "干扰源数据维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(interferenceDataService.deleteInterferenceDataByIds(ids));
    }
}
